﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX;

namespace DirectX_CS
{
    public partial class VectorUpDown : UserControl
    {
        bool settingValues = false;
        bool userChangesOnly = true;
        public delegate void ValueChanged(Vector3 value);
        public event ValueChanged mValueChanged;

        public float X
        {
            get { return (float)nudX.Value; }
            set
            {
                settingValues = true;
                nudX.Value = (decimal)value;
            }
        }
        public float Y
        {
            get { return (float)nudY.Value; }
            set
            {
                settingValues = true;
                nudY.Value = (decimal)value;
            }
        }
        public float Z
        {
            get { return (float)nudZ.Value; }
            set
            {
                settingValues = true;
                nudZ.Value = (decimal)value;
            }
        }
        public void SetAllMaxValues(float maxValue)
        {
            nudX.Maximum = (decimal)maxValue;
            nudY.Maximum = (decimal)maxValue;
            nudZ.Maximum = (decimal)maxValue;
        }
        public void SetAllMinValues(float minValue)
        {
            nudX.Minimum = (decimal)minValue;
            nudY.Minimum = (decimal)minValue;
            nudZ.Minimum = (decimal)minValue;
        }
        public void SetAllValues(float minValue, float maxValue)
        {
            SetAllMinValues(minValue); 
            SetAllMaxValues(maxValue);
        }
        public void SetAllIncrement(float incrementValue)
        {
            nudX.Increment = (decimal)incrementValue;
            nudY.Increment = (decimal)incrementValue;
            nudZ.Increment = (decimal)incrementValue;
        }
        public void SetAllDecimalPlaces(int decimalPlaces)
        {
            nudX.DecimalPlaces = decimalPlaces;
            nudY.DecimalPlaces = decimalPlaces;
            nudZ.DecimalPlaces = decimalPlaces;
        }
        public FlowDirection Direction
        {
            get { return flpContent.FlowDirection; }
            set
            {
                flpContent.FlowDirection = value;
                this.Size = flpContent.Size;

            }
        }
        public VectorUpDown()
        {
            InitializeComponent();
        }
        public Vector3 Value
        {
            get { return new Vector3((float)nudX.Value, (float)nudY.Value, (float)nudZ.Value); }
            set
            {

				settingValues = true;
				try
				{
					nudX.Value = (decimal)value.X;
				}
				catch (Exception e1)
				{
					nudX.Value = nudX.Maximum;
				}
				try
				{
					nudY.Value = (decimal)value.Y;
				}
				catch (Exception e2)
				{
					nudY.Value = nudY.Maximum;
				}
				try
				{
					nudZ.Value = (decimal)value.Z;
				}
				catch (Exception e3)
				{
					nudZ.Value = nudZ.Maximum;
				}
				settingValues = false;
				if (!userChangesOnly)
				{
					mValueChanged.Invoke(value);
				}

				
            }
        }

        private void nudValueAllChanged(object sender, EventArgs e)
        {
            if (!settingValues)
            {
				if (mValueChanged !=null)
					mValueChanged.Invoke(new Vector3((float)nudX.Value, (float)nudY.Value, (float)nudZ.Value));
            }
        }
    }
}
